<template>
  <div>
    <div>
      <el-input
        v-model="input"
        style="width: 150px"
        placeholder="请销售员名"
        @change="findOrders(input)"
      ></el-input>
    </div>
    <el-table :data="ordersAllData" style="width: 100%">
      <el-table-column prop="startTime" label="下单时间"> </el-table-column>
      <el-table-column prop="state" label="订单状态">
        <template slot-scope="scope">
          <el-button type="success" disabled v-if="scope.row.state == 3"
            >支付成功</el-button
          >
          <el-button type="info" disabled v-if="scope.row.state != 3"
            >尚未支付</el-button
          >
        </template>
      </el-table-column>
      <el-table-column prop="termination" label="是否退保">
        <template slot-scope="scope">
          <el-button type="info" disabled v-if="scope.row.termination == 2"
            >已退保</el-button
          >
          <el-button
            type="success"
            @click="cut(scope.row._id)"
            v-if="scope.row.termination == 1"
            >未退保</el-button
          >
        </template>
      </el-table-column>
      <el-table-column prop="endTime" label="下单时间"> </el-table-column>
      <el-table-column prop="salesId.name" label="销售员"> </el-table-column>
      <el-table-column prop="customersId.name" label="客户"> </el-table-column>
      <el-table-column prop="productsId.name" label="产品"> </el-table-column>
      <el-table-column prop="claimsId.name" label="理赔"> </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            type="danger"
            icon="el-icon-delete"
            circle
            @click="dele(scope.row._id)"
          >
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

  <script>
import { createNamespacedHelpers } from "vuex";
const { mapActions, mapState } = createNamespacedHelpers("adminsOrders");
export default {
  data() {
    return {
      value: true,
        input: "",
    };
  },
  mounted() {
    this.getOrdersList();
  },
  computed: {
    ...mapState(["ordersAllData"]),
  },
  methods: {
    ...mapActions(["getOrdersList", "applyOrders", "deleteOrders",'getOrdersSalesIdList']),
    async cut(value) {
      const data = await this.applyOrders({ _id: value });
      if (data.data.code) {
        const h = this.$createElement;
        this.$notify({
          message: h("i", { style: "color: teal" }, "以退保"),
        });
        this.getOrdersList();
      } else {
        const h = this.$createElement;
        this.$notify({
          message: h("i", { style: "color: teal" }, "退保不成功"),
        });
      }
    },
    async dele(value) {
      const data = await this.deleteOrders({ _id: value });
      if (data.data.code) {
        const h = this.$createElement;
        this.$notify({
          message: h("i", { style: "color: teal" }, "以删除"),
        });
        this.getOrdersList();
      } else {
        const h = this.$createElement;
        this.$notify({
          message: h("i", { style: "color: teal" }, "删除不成功"),
        });
      }
    },
  findOrders(value){
this.getOrdersSalesIdList({salesId:value})
  }
  },
};
</script>

<style>
</style>